package objbo.xmlparser.controls.action;

import objbo.xmlparser.model.bean.ElementBean;
import objbo.xmlparser.view.interfaces.ElementInterFace;
import objbo.xmlparser.view.interfaces.UIInterFace;
import objbo.xmlparser.view.ui.AttributeListUI;

import org.eclipse.jface.action.Action;

public class AttributeListAddAction extends Action
{
	private UIInterFace uIInterFace = null;
	private ElementInterFace elementInterFace = null;
	private AttributeListUI ui = null;
	
	public AttributeListAddAction(ElementInterFace elementInterFace, UIInterFace uIInterFace)
	{
		this.uIInterFace = uIInterFace;
		this.elementInterFace = elementInterFace;
	}
	
	public void setAttributeListUI(AttributeListUI ui)
	{
		this.ui = ui;
	}
	
	
	@Override
	public void run()
	{
		Object[] data = null;
		ElementBean elementBean = null;
		String name = null;
		String value = null;
		
		if(ui.getdata() == null)
		{
			return;
		}
		
		data = ui.getdata();
		
		elementBean = (ElementBean) data[0];
		name = (String) data[1];
		value = (String) data[2];
		
		System.out.println(name + "," +value);
		
		if(data == null || elementBean == null)
		{return;}
		
		this.elementInterFace.AddAttribute(elementBean, name, value);
		this.uIInterFace.setTabElementData(elementBean);
		this.uIInterFace.refreshTreeUI();
	}

}
